<?php
date_default_timezone_set('PRC');
session_start();
if ($_SESSION["islogin"] !== 'igiveyouthepower') {
    echo "<script language=JavaScript>\r\n";
    echo "alert('请先登录');\r\n";
    echo "location.href='../index.php'\r\n";
    echo "</script>";
}
require_once('../config.php');
$conn = mysqli_connect($cfg_dbhost, $cfg_dbuser, $cfg_dbpwd,$cfg_dbname);

$lang = $_GET["lang"];
$bname = $_GET["bname"];
if ($_SESSION["thetype"] == "管理员" || $_SESSION["thetype"] == "超级管理员") {
    $sql = "select * from ph_" . $lang . " where 1=1";
} else {
    $sql = "select * from ph_" . $lang . " where 1=1 and user_name='" . $_SESSION["managername"] . "'";
}
if ($bname !== '' && isset($bname)) {
    $sql .= " and bname ='" . $bname . "'";
}
$result = mysqli_query($conn,$sql);

require '../PHPExcel/PHPExcel.php';
require '../PHPExcel/PHPExcel/Writer/Excel2007.php';

//创建一个excel
$objPHPExcel = new PHPExcel();

$objWriter = new PHPExcel_Writer_Excel2007($objPHPExcel);

//设置当前的sheet
$objPHPExcel->setActiveSheetIndex(0);
//设置sheet的name,excel文件名
$fileName = $bname . "-" . date('Ymdhis', time());
//$objPHPExcel->getActiveSheet()->setTitle($fileName);

//合并单元格、表头
//$objPHPExcel->getActiveSheet()->mergeCells('A1:O1');
$objPHPExcel->getActiveSheet()->setCellValue('A1', 'TemplateType=Sports');
$objPHPExcel->getActiveSheet()->setCellValue('B1', 'Version=2013.0903');
$objPHPExcel->getActiveSheet()->setCellValue('C1', 'The top 3 rows are for Amazon.com use only. Do not modify or delete the top 3 rows.');
$objPHPExcel->getActiveSheet()->mergeCells('C1:J1');
$objPHPExcel->getActiveSheet()->setCellValue('K1', 'Offer - Offer Information - These attributes are required to make your item buyable for customers on the site.');
$objPHPExcel->getActiveSheet()->mergeCells('K1:O1');
$objPHPExcel->getActiveSheet()->setCellValue('P1', 'Dimension - These attributes specify the size and weight of a product');
$objPHPExcel->getActiveSheet()->mergeCells('P1:S1');
$objPHPExcel->getActiveSheet()->setCellValue('T1', 'Discovery - These attributes have an effect on how customers can find your product on the site using browse or search');
$objPHPExcel->getActiveSheet()->mergeCells('T1:AE1');
$objPHPExcel->getActiveSheet()->setCellValue('AF1', 'Image - Image Information - See Image Instructions tab for details.');
$objPHPExcel->getActiveSheet()->mergeCells('AF1:AO1');
$objPHPExcel->getActiveSheet()->setCellValue('AP1', 'Variation - Populate these attributes if your product is available in different variations (for example color or wattage)');
$objPHPExcel->getActiveSheet()->mergeCells('AP1:AS1');
$objPHPExcel->getActiveSheet()->setCellValue('AT1', 'Ungrouped - These attributes create rich product listings for your buyers.');
$objPHPExcel->getActiveSheet()->mergeCells('AT1:AW1');

$objPHPExcel->getActiveSheet()->getStyle('A1:AW1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);

$headinfo1 = array(
    'SKU',
    'Product ID',
    'Product ID Type',
    'Item Title',
    'Brand Name',
    'Manufacturer',
    'Manufacturer Part Number',
    'Product Description',
    'Feed Product Type',
    'Update Delete',
    'Standard Price',
    'Currency',
    'Quantity',
    'Condition Type',
    'Item Condition Note',
    'Shipping Weight',
    'Website Shipping Weight Unit Of    Measure',
    'Item Weight',
    'Item Weight Unit Of Measure',
    'Key Product Features1',
    'Key Product Features2',
    'Key Product Features3',
    'Key Product Features4',
    'Key Product Features5',
    'Recommended Browse Node1',
    'Recommended Browse Node2',
    'Search Terms1',
    'Search Terms2',
    'Search Terms3',
    'Search Terms4',
    'Search Terms5',
    'Main Image URL',
    'Swatch Image Url',
    'Other Image URL1',
    'Other Image URL2',
    'Other Image URL3',
    'Other Image URL4',
    'Other Image URL5',
    'Other Image URL6',
    'Other Image URL7',
    'Other Image URL8',
    'Parentage',
    'Parent SKU',
    'Relationship Type',
    'Variation Theme',
    'Color',
    'Color Map',
    'Size',
    'Size Map'
);

//设置指定单元格宽度
for ($i = 0; $i < count($headinfo1); $i++) {
    $objPHPExcel->getActiveSheet()->getColumnDimension(IntToChr($i))->setWidth(30);
}

//水平居中
$objPHPExcel->getActiveSheet()->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
//设置起始位置生成表格
$startX = 'A';
$startY = '2';
for ($i = 0; $i < count($headinfo1); $i++) {
    //水平居中
    $objPHPExcel->getActiveSheet()->getStyle($startX . $startY)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    //垂直居中
    $objPHPExcel->getActiveSheet()->getStyle($startX . $startY)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
    $objPHPExcel->getActiveSheet()->setCellValue($startX++ . $startY, $headinfo1[$i]);
    //设置单元格属性(文本属性)
    $objPHPExcel->getActiveSheet()->getStyle($startX . $startY)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
}
$headinfo2 = array(
    'item_sku',
    'external_product_id',
    'external_product_id_type',
    'item_name',
    'brand_name',
    'manufacturer',
    'part_number',
    'product_description',
    'feed_product_type',
    'update_delete',
    'standard_price',
    'currency',
    'quantity',
    'condition_type',
    'condition_note',
    'website_shipping_weight',
    'website_shipping_weight_unit_of_measure',
    'item_weight',
    'item_weight_unit_of_measure',
    'bullet_point1',
    'bullet_point2',
    'bullet_point3',
    'bullet_point4',
    'bullet_point5',
    'recommended_browse_nodes1',
    'recommended_browse_nodes2',
    'generic_keywords1',
    'generic_keywords2',
    'generic_keywords3',
    'generic_keywords4',
    'generic_keywords5',
    'main_image_url',
    'swatch_image_url',
    'other_image_url1',
    'other_image_url2',
    'other_image_url3',
    'other_image_url4',
    'other_image_url5',
    'other_image_url6',
    'other_image_url7',
    'other_image_url8',
    'parent_child',
    'parent_sku',
    'relationship_type',
    'variation_theme',
    'color_name',
    'color_map',
    'size_name',
    'size_map'
);
$startX = 'A';
$startY = '3';
for ($i = 0; $i < count($headinfo2); $i++) {
    //水平居中
    $objPHPExcel->getActiveSheet()->getStyle($startX . $startY)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
    //垂直居中
    $objPHPExcel->getActiveSheet()->getStyle($startX . $startY)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
    $objPHPExcel->getActiveSheet()->setCellValue($startX++ . $startY, $headinfo2[$i]);
    //设置单元格属性(文本属性)
    $objPHPExcel->getActiveSheet()->getStyle($startX . $startY)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);
}

//设置填充的样式和背景色
$objPHPExcel->getActiveSheet()->getStyle('A1:J3')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle('A1:J3')->getFill()->getStartColor()->setARGB('FFCC00');

$objPHPExcel->getActiveSheet()->getStyle('K1:O3')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle('K1:O3')->getFill()->getStartColor()->setARGB('FF0000');

$objPHPExcel->getActiveSheet()->getStyle('P1:S3')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle('P1:S3')->getFill()->getStartColor()->setARGB('99CCFF');

$objPHPExcel->getActiveSheet()->getStyle('T1:AE3')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle('T1:AE3')->getFill()->getStartColor()->setARGB('99CC00');

$objPHPExcel->getActiveSheet()->getStyle('AF1:AO3')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle('AF1:AO3')->getFill()->getStartColor()->setARGB('FFFF00');

$objPHPExcel->getActiveSheet()->getStyle('AP1:AS3')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle('AP1:AS3')->getFill()->getStartColor()->setARGB('FF8080');

$objPHPExcel->getActiveSheet()->getStyle('AT1:AW3')->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
$objPHPExcel->getActiveSheet()->getStyle('AT1:AW3')->getFill()->getStartColor()->setARGB('FF9900');

$mun = 3;
while ($row = mysqli_fetch_array($result)) {
    $key1 = "";
    $key2 = "";
    $key3 = "";
    $key4 = "";
    $key5 = "";
    $des1 = "";
    $des2 = "";
    $des3 = "";
    $des4 = "";
    $des5 = "";
	$f=0;
    $mun++;
    if (is_array($row) && count($row) > 0) {
        if (!empty($row['keywords'])) {
            $key = explode("\r\n", $row['keywords']);
            if (!empty($key[0])) {
                $key1 = $key[0];
            }
            if (!empty($key[1])) {
                $key2 = $key[1];
            }
            if (!empty($key[2])) {
                $key3 = $key[2];
            }
            if (!empty($key[3])) {
                $key4 = $key[3];
            }
            if (!empty($key[4])) {
                $key5 = $key[4];
            }
        }
        if (!empty($row['sketch'])){$maidian=$row['sketch'];}else{$maidian=$row['content'];}
            $spliter = "<br/>";
			if(strpos($maidian,$spliter)==0){$f=1;}
			if(strpos($maidian, $spliter) !== false) {
        $des = explode($spliter, $maidian);
    } else {
        $des = explode("<br/>", $maidian);
    }
    $des1 = $des[$f];
    $des2 = $des[$f+1];
    $des3 = $des[$f+2];
    $des4 = $des[$f+3];
    $des5 = $des[$f+4];
        //}
        $sqla="select * from ph_img where id in(select imgid from(select imgid from ph_proimg where proid='".$row["ID"]."' and btid is null order by px,id asc) t order by px,id asc)";
        $resulta = mysqli_query($conn,$sqla);
        while ($rowa = mysqli_fetch_array($resulta)) {
            if (!empty($rowa['imgpath'])) {
                $img1 = "http://" . $_SERVER['SERVER_NAME'] . $rowa['imgpath'];
            } else {
                $img1 = "";
            }
            $rowa = mysqli_fetch_array($resulta);
            if (!empty($rowa['imgpath'])) {
                $img2 = "http://" . $_SERVER['SERVER_NAME'] . $rowa['imgpath'];
            } else {
                $img2 = "";
            }
            $rowa = mysqli_fetch_array($resulta);
            if (!empty($rowa['imgpath'])) {
                $img3 = "http://" . $_SERVER['SERVER_NAME'] . $rowa['imgpath'];
            } else {
                $img3 = "";
            }
            $rowa = mysqli_fetch_array($resulta);
            if (!empty($rowa['imgpath'])) {
                $img4 = "http://" . $_SERVER['SERVER_NAME'] . $rowa['imgpath'];
            } else {
                $img4 = "";
            }
            $rowa = mysqli_fetch_array($resulta);
            if (!empty($rowa['imgpath'])) {
                $img5 = "http://" . $_SERVER['SERVER_NAME']  . $rowa['imgpath'];
            } else {
                $img5 = "";
            }
            $rowa = mysqli_fetch_array($resulta);
            if (!empty($rowa['imgpath'])) {
                $img6 = "http://" . $_SERVER['SERVER_NAME'] . $rowa['imgpath'];
            } else {
                $img6 = "";
            }
            $rowa = mysqli_fetch_array($resulta);
            if (!empty($rowa['imgpath'])) {
                $img7 = "http://" . $_SERVER['SERVER_NAME'] . $rowa['imgpath'];
            } else {
                $img7 = "";
            }
            $rowa = mysqli_fetch_array($resulta);
            if (!empty($rowa['imgpath'])) {
                $img8 = "http://" . $_SERVER['SERVER_NAME'] . $rowa['imgpath'];
            } else {
                $img8 = "";
            }
            $rowa = mysqli_fetch_array($resulta);
            if (!empty($rowa['imgpath'])) {
                $img9 = "http://" . $_SERVER['SERVER_NAME']  . $rowa['imgpath'];
            } else {
                $img9 = "";
            }
        }
        $rowa = null;
        unset($rowa);


        $sqls = "select * from ph_shuxing where proid='" . $row['ID'] . "' order by ID asc";
        $results = mysqli_query($conn,$sqls);
        if (mysqli_num_rows($results) < 1) {
            $upc = "UPC";
            $sku = $row['skucode'];
            $parent = "";
        } else {
            $upc = "";
            $sku = "";
            $parent = "parent";
        }
//        $content = str_replace("\r\n", htmlentities('<br/>'), $row['content']);
//        $content = htmlentities($content);
        $content = handContent($row['content']);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A' . $mun, $row['code']);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B' . $mun, $sku);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('C' . $mun, $upc);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('D' . $mun, $row['proname']);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('E' . $mun, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('F' . $mun, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('G' . $mun, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('H' . $mun, $content);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('I' . $mun, 'HOME');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('J' . $mun, 'Update');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('K' . $mun, $row['saleprice']);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('L' . $mun, $row['coin']);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('M' . $mun, $row['kucun']);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('N' . $mun, 'New');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('O' . $mun, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('P' . $mun, $row['weight']);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('Q' . $mun, 'KG');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('R' . $mun, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('S' . $mun, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('T' . $mun, $des1);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('U' . $mun, $des2);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('V' . $mun, $des3);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('W' . $mun, $des4);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('X' . $mun, $des5);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('Y' . $mun, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('Z' . $mun, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AA' . $mun, $key1);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AB' . $mun, $key2);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AC' . $mun, $key3);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AD' . $mun, $key4);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AE' . $mun, $key5);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AF' . $mun, $img1);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AG' . $mun, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AH' . $mun, $img2);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AI' . $mun, $img3);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AJ' . $mun, $img4);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AK' . $mun, $img5);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AL' . $mun, $img6);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AM' . $mun, $img7);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AN' . $mun, $img8);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AO' . $mun, $img9);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AP' . $mun, $parent);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AQ' . $mun, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AR' . $mun, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AS' . $mun, $row['btname']);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AT' . $mun, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AU' . $mun, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AV' . $mun, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AW' . $mun, '');
    }
    while ($rows = mysqli_fetch_array($results)) {
        $mun++;
        $btimg1 = "";
        $btimg2 = "";
        $btimg3 = "";
        $btimg4 = "";
        $btimg5 = "";
        $btimg6 = "";
        $btimg7 = "";
        $btimg8 = "";
        $btimg9 = "";
        if (strpos($rows['cname'], ",") !== false) {
            $cname = explode(",", $rows['cname']);
            $cname1 = $cname[0];
            $cname2 = $cname[1];
        } else {
            $cname1 = $rows['cname'];
            $cname2 = "";
        }
        $sqlb="select * from ph_img where id in(select imgid from(select imgid from ph_proimg where btid='".$rows["ID"]."' order by id asc) t order by id asc)";
        $resultb = mysqli_query($conn,$sqlb);
        while ($rowb = mysqli_fetch_array($resultb)) {

            if (!empty($rowb['imgpath'])) {
                $btimg1 = "http://" . $_SERVER['SERVER_NAME'] . $rowb['imgpath'];
            } else {
                $btimg1 = $img1;
            }
            $rowb = mysqli_fetch_array($resultb);
            if (!empty($rowb['imgpath'])) {
                $btimg2 = "http://" . $_SERVER['SERVER_NAME'] . $rowb['imgpath'];
            }
            $rowb = mysqli_fetch_array($resultb);
            if (!empty($rowb['imgpath'])) {
                $btimg3 = "http://" . $_SERVER['SERVER_NAME'] . $rowb['imgpath'];
            }
            $rowb = mysqli_fetch_array($resultb);
            if (!empty($rowb['imgpath'])) {
                $btimg4 = "http://" . $_SERVER['SERVER_NAME'] . $rowb['imgpath'];
            }
            $rowb = mysqli_fetch_array($resultb);
            if (!empty($rowb['imgpath'])) {
                $btimg5 = "http://" . $_SERVER['SERVER_NAME'] . $rowb['imgpath'];
            }
            $rowb = mysqli_fetch_array($resultb);
            if (!empty($rowb['imgpath'])) {
                $btimg6 = "http://" . $_SERVER['SERVER_NAME'] . $rowb['imgpath'];
            }
            $rowb = mysqli_fetch_array($resultb);
            if (!empty($rowb['imgpath'])) {
                $btimg7 = "http://" . $_SERVER['SERVER_NAME'] . $rowb['imgpath'];
            }
            $rowb = mysqli_fetch_array($resultb);
            if (!empty($rowb['imgpath'])) {
                $btimg8 = "http://" . $_SERVER['SERVER_NAME'] . $rowb['imgpath'];
            }
            $rowb = mysqli_fetch_array($resultb);
            if (!empty($rowb['imgpath'])) {
                $btimg9 = "http://" . $_SERVER['SERVER_NAME'] . $rowb['imgpath'];
            }


        }
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A' . $mun, $row['code'] . '-' . $rows['cname']);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('B' . $mun, $rows['skucode']);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('C' . $mun, 'UPC');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('D' . $mun, $row['proname'] . "-" . $rows['cname']);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('E' . $mun, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('F' . $mun, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('G' . $mun, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('H' . $mun, $content);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('I' . $mun, 'HOME');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('J' . $mun, 'Update');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('K' . $mun, $rows['saleprice']);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('L' . $mun, $row['coin']);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('M' . $mun, $rows['kucun']);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('N' . $mun, 'New');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('O' . $mun, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('P' . $mun, $row['weight']);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('Q' . $mun, 'KG');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('R' . $mun, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('S' . $mun, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('T' . $mun, $des1);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('U' . $mun, $des2);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('V' . $mun, $des3);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('W' . $mun, $des4);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('X' . $mun, $des5);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('Y' . $mun, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('Z' . $mun, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AA' . $mun, $key1);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AB' . $mun, $key2);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AC' . $mun, $key3);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AD' . $mun, $key4);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AE' . $mun, $key5);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AF' . $mun, $btimg1);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AG' . $mun, '');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AH' . $mun, $btimg2);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AI' . $mun, $btimg3);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AJ' . $mun, $btimg4);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AK' . $mun, $btimg5);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AL' . $mun, $btimg6);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AM' . $mun, $btimg7);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AN' . $mun, $btimg8);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AO' . $mun, $btimg9);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AP' . $mun, 'child');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AQ' . $mun, $row['code']);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AR' . $mun, 'Variation');
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AS' . $mun, $row['btname']);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AT' . $mun, $cname1);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AU' . $mun, $cname1);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AV' . $mun, $cname2);
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue('AW' . $mun, $cname2);
    }


}
/*
 * Job:导出无数据空白页面问题修改
 * 下面代码从IF中拿到外面
 */
ob_end_clean();
header("Pragma: public");
header("Expires: 0");
header('Cache-Control: max-age=0'); //禁止缓存
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");
header('Content-Disposition:attachment;filename=' . $fileName . '.xls');
header("Content-Transfer-Encoding:binary");
$objWriter->save('php://output');


/**
 * 数字转字母 （类似于Excel列标）
 * @param Int $index 索引值
 * @param Int $start 字母起始值
 * @return String 返回字母
 */
function IntToChr($index, $start = 65)
{
    $str = '';
    if (floor($index / 26) > 0) {
        $str .= IntToChr(floor($index / 26) - 1);
    }
    return $str . chr($index % 26 + $start);
}

/**
 * 处理字符串中多个连续br替换一个
 */
function handContent($str = ''){
    $arr = array_filter(explode("<br/>",$str));
    return implode("<br/>",$arr);
}